new Vue({
  el: '#build',
  data() {
    return {
      dialog: false,
      editForm: {
        name: '',
        createYear: '',
        remark: ''
      },
      roleRules: {
        name: [{required: true, message: '名字必填', tirgger: 'blur'}],
        createYear: [{required: true, message: '建造时间必填', tirgger: 'blur'}],
        remark: [{required: true, message: '备注必填', tirgger: 'blur'}]
      },
      dialogImageUrl: '',
      dialogVisible: false
    }
  },
  methods: {
    test() {
      console.log('test')
    },
    showDialog () {
      this.dialog = !this.dialog;
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleSuccess (response) {
      if (response.code === 0) {
        this.editForm.images = response.data
      }
    },
    onSave() {
      const that = this;
      this.$refs['ruleForm'].validate(function(valid){
        if (valid) {
          axios.post('/build/', that.editForm).then(function(res){
            that.clearForm();
            that.showDialog();
            window.location.reload();
          })
        }
      })
    },
    clearForm() {
      this.$refs['ruleForm'].clearValidate();
      this.$refs['ruleForm'].resetFields();
    },
    goBack() {
      window.location.href = '/';
    }
  }
})
